home *** CD-ROM | disk | FTP | other *** search
- unit Demounit;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls, Menus, Htmlview, StdCtrls, HtmlSubs;
-
- const
- MaxHistories = 6; {size of History list}
- type
- TForm1 = class(TForm)
- OpenDialog: TOpenDialog;
- MainMenu: TMainMenu;
- Panel1: TPanel;
- Panel2: TPanel;
- Panel3: TPanel;
- Viewer: THTMLViewer;
- File1: TMenuItem;
- Open: TMenuItem;
- options1: TMenuItem;
- ShowImages: TMenuItem;
- Background1: TMenuItem;
- clBtnFace1: TMenuItem;
- clWindow1: TMenuItem;
- Edit1: TEdit;
- Reload: TButton;
- BackButton: TButton;
- FwdButton: TButton;
- HistoryMenuItem: TMenuItem;
- Exit: TMenuItem;
- N1: TMenuItem;
- procedure OpenFileClick(Sender: TObject);
- procedure HotSpotChange(Sender: TObject; const URL: string);
- procedure HotSpotClick(Sender: TObject; const URL: string;
- var Handled: boolean);
- procedure ShowImagesClick(Sender: TObject);
- procedure ColorClick(Sender: TObject);
- procedure ReloadClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FwdBackClick(Sender: TObject);
- procedure HistoryClick(Sender: TObject);
- procedure HistoryChange(Sender: TObject);
- procedure ExitClick(Sender: TObject);
- private
- { Private declarations }
- SndHandle : THandle;
- PlaySound : function (lpszSoundName: PChar; uFlags: Word): Bool;
- Histories: array[0..MaxHistories-1] of TMenuItem;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- I: integer;
- begin
- clBtnFace1.Checked := True;
- OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
-
- {make sure mmsystem.dll exists before calling sndPlaySound}
- SndHandle := LoadLibrary('mmsystem.dll');
- if SndHandle >= 32 then
- @PlaySound := GetProcAddress(SndHandle, 'sndPlaySound');
-
- Viewer.HistoryMaxCount := MaxHistories; {defines size of history list}
-
- for I := 0 to MaxHistories-1 do
- begin {create the MenuItems for the history list}
- Histories[I] := TMenuItem.Create(HistoryMenuItem);
- HistoryMenuItem.Insert(I, Histories[I]);
- with Histories[I] do
- begin
- Visible := False;
- OnClick := HistoryClick;
- Tag := I;
- end;
- end;
- if (ParamCount >= 1) then
- Viewer.LoadFromFile(ParamStr(1)); {Parameter is file to load}
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- if SndHandle >= 32 then FreeLibrary(SndHandle);
- end;
-
- procedure TForm1.OpenFileClick(Sender: TObject);
- begin
- if Viewer.CurrentFile <> '' then
- OpenDialog.InitialDir := ExtractFilePath(Viewer.CurrentFile);
- if OpenDialog.Execute then
- begin
- Viewer.LoadFromFile(OpenDialog.Filename);
- Caption := Viewer.DocumentTitle;
- Reload.Enabled := Viewer.CurrentFile <> '';
- end;
- end;
-
- procedure TForm1.HotSpotChange(Sender: TObject; const URL: string);
- {mouse moved over or away from a hot spot. Change the status line}
- begin
- Panel1.Caption := URL;
- end;
-
- procedure TForm1.HotSpotClick(Sender: TObject; const URL: string;
- var Handled: boolean);
- {This routine handles what happens when a hot spot is clicked. The assumption
- is made that DOS filenames are being used. .EXE and .WAV files are handled
- here, but other file types could be easily added.
-
- If the URL is handled here, set Handled to True. If not handled here, set it
- to False and ThtmlViewer will handle it.}
- const
- snd_Async = $0001; { play asynchronously }
- var
- PC: array[0..255] of char;
- S: string[70];
- Ext: string[5];
- I, J: integer;
-
- begin
- Handled := False;
- I := Pos(':', URL);
- J := Pos('FILE:', UpperCase(URL));
- if (I <= 2) or (J > 0) then
- begin {apparently the URL is a filename}
- S := Viewer.HTMLExpandFileName(URL);
- Ext := Uppercase(ExtractFileExt(S));
- if Ext = '.WAV' then
- begin
- Handled := True;
- if Assigned(PlaySound) then
- PlaySound(StrPCopy(PC, S), snd_ASync);
- end
- else if Ext = '.EXE' then
- begin
- Handled := True;
- WinExec(StrPCopy(PC, S), sw_Show);
- end;
- {else ignore other extensions}
- Edit1.Text := URL;
- end
- else Edit1.Text := URL; {other protocall, mailto:, ftp:, etc.}
- end;
-
- procedure TForm1.ShowImagesClick(Sender: TObject);
- {The Show Images menu item was clicked}
- begin
- With Viewer do
- begin
- ViewImages := not ViewImages;
- (Sender as TMenuItem).Checked := ViewImages;
- end;
- end;
-
- procedure TForm1.ColorClick(Sender: TObject);
- {one of the color options on the menu was clicked}
- begin
- with Sender as TMenuItem do
- begin
- if Sender = clBtnFace1 then
- begin
- Viewer.Color := clBtnFace;
- Checked := True;
- clWindow1.Checked := False;
- end
- else
- begin
- Viewer.Color := clWindow;
- Checked := True;
- clBtnFace1.Checked := False;
- end ;
- end;
- end;
-
- procedure TForm1.ReloadClick(Sender: TObject);
- {the Reload button was clicked}
- var
- Pos: LongInt;
- begin
- with Viewer do
- begin
- Pos := Position; {save the postion}
- LoadFromFile(CurrentFile); {load again}
- Position := Pos; {restore position}
- end;
- end;
-
- procedure TForm1.FwdBackClick(Sender: TObject);
- {Either the Forward or Back button was clicked}
- begin
- with Viewer do
- begin
- if Sender = BackButton then
- HistoryIndex := HistoryIndex +1
- else
- HistoryIndex := HistoryIndex -1;
- end;
- end;
-
- procedure TForm1.HistoryChange(Sender: TObject);
- {This event occurs when something changes history list}
- var
- I: integer;
- begin
- with Sender as ThtmlViewer do
- begin
- {check to see which buttons are to be enabled}
- FwdButton.Enabled := HistoryIndex > 0;
- BackButton.Enabled := HistoryIndex < History.Count-1;
-
- {Enable and caption the appropriate history menuitems}
- HistoryMenuItem.Visible := History.Count > 0;
- for I := 0 to MaxHistories-1 do
- with Histories[I] do
- if I < History.Count then
- Begin
- Caption := History.Strings[I];
- Visible := True;
- Checked := I = HistoryIndex;
- end
- else Histories[I].Visible := False;
- Caption := DocumentTitle; {keep the caption updated}
- end;
- end;
-
- procedure TForm1.HistoryClick(Sender: TObject);
- {A history list menuitem got clicked on}
- begin
- {Changing the HistoryIndex loads and positions the appropriate document}
- Viewer.HistoryIndex := (Sender as TMenuItem).Tag;
- end;
-
- procedure TForm1.ExitClick(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-